package trading.ctm.yunjing.module.auction.fragment

import android.content.Intent
import android.os.Bundle
import android.support.v4.content.LocalBroadcastManager
import android.support.v7.widget.LinearLayoutManager
import android.view.View
import cc.vv.baselibrary.fragment.BaseFragment
import cc.vv.baselibrary.view.BTLoadMoreView
import cc.vv.baselibrary.view.BaseTopBarView
import cc.vv.lkbasecomponent.util.LKSPUtil
import kotlinx.android.synthetic.main.fragment_auction.*
import trading.ctm.yunjing.R
import trading.ctm.yunjing.module.auction.adapter.AuctionAdapter

/**
 * 拍卖
 */
class AuctionFragment : BaseFragment() {

    var adapter: AuctionAdapter? = null
    override fun initLayoutRes(): Int {
        return R.layout.fragment_auction
    }

    override fun initView(bundle: Bundle?) {
        super.initView(bundle)
        srl_af_auction.setColorSchemeResources(R.color.color_693C26)
        rv_af_auction_list.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
    }

    override fun onResume() {
        super.onResume()
        val i = LKSPUtil.getInstance().getInt("isTableHost", 1)
        if(i == 0){
            btbv_af_auction.iv_ljtb_left_back.visibility = View.VISIBLE
            LKSPUtil.getInstance().put("isTableHost", 1)
        }else{
            btbv_af_auction.iv_ljtb_left_back.visibility = View.GONE
        }
    }

    override fun initAction(bundle: Bundle?) {
        super.initAction(bundle)
        var list = arrayListOf<String>()
        for (i in 0 until 50) {
            list.add("AuctionFragment $i")
        }
        adapter = AuctionAdapter(R.layout.view_hav_auction, list)

        adapter!!.setLoadMoreView(BTLoadMoreView())
        rv_af_auction_list.adapter = adapter
        adapter!!.setOnLoadMoreListener({
            adapter!!.loadMoreComplete()
        }, rv_af_auction_list)
        adapter!!.loadMoreEnd(true)
        srl_af_auction.setOnRefreshListener {
            srl_af_auction.isRefreshing = false
        }

       

        btbv_af_auction.setEventInterface(object : BaseTopBarView.EventInterface {
            override fun leftOnClick() {
                val intent = Intent("fragment")
                intent.putExtra("fragment_key", 0)
                LocalBroadcastManager.getInstance(context).sendBroadcast(intent)
            }

            override fun leftCloseClick() {
            }

            override fun rightOnClick() {
            }

        })


    }



}